﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using XYAC.Framework.WohuaMesExtend.IHI.Extensions;

namespace XYAC.Framework.WohuaMesExtend.IHI.OracleRemoteDB
{
    public class OracleMesContext : DbContext
    {
        public OracleMesContext(IOptionsMonitor<AppConfig> moduleConfig) : base()
        {
            this.ConnectionString = moduleConfig.CurrentValue?.OracleMesConnectionString;
        }

        public string ConnectionString { get; }

        public DbSet<YB_LOT_INSPECT> YB_LOT_INSPECT { get; set; }
        public DbSet<YB_PROCESS_STEP> YB_PROCESS_STEP { get; set; }
        public DbSet<YB_Technology_Header> YB_Technology_Header { get; set; }
        public DbSet<YB_Technology_Line> YB_Technology_Line { get; set; }


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<YB_PROCESS_STEP>()
                        .Property(e => e.LJ_ID)
                        .ValueGeneratedOnAdd(); // 确保主键是自增的

            base.OnModelCreating(modelBuilder);
        }

        /// <summary>
        /// 当DB发生OnConfiguring用于配置数据库
        /// </summary>
        /// <param name="optionsBuilder"></param>
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // 配置 SQL Server 数据库连接字符串
            optionsBuilder.UseOracle(ConnectionString, option => option.UseOracleSQLCompatibility("12"));
            //optionsBuilder.UseSqlServer(ConnectionString);
        }
    }
}
